﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Adatkezelo.Classes;

namespace NEMProjectWebApp.Pages.Oktato {
    public partial class targyakKezelese : System.Web.UI.Page {
        Login_Kezeles login = new Login_Kezeles();
        TargyKezelo targykez = new TargyKezelo();
        protected void Page_Load(object sender, EventArgs e) {
            string redirect = login.BelepesiJogkorEll(Session, 3);
            if (redirect.Length > 0) Response.Redirect(redirect);
        }

        protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e) {
        }
        SQLDataManipulation sql = new SQLDataManipulation();
        protected void UpdatePanel1_Load(object sender, EventArgs e) {
            if (TargyakListBox.SelectedItem != null) {
                IDLabel.Text = TargyakListBox.SelectedItem.Value;
                sql.OpenConn();
                System.Data.SqlClient.SqlDataReader result = sql.getDataByID(Convert.ToInt32(TargyakListBox.SelectedItem.Value), "Targy", "T_ID");
                try {
                    result.Read();
                    labelKezd.Text = result["Kezd"].ToString();
                    labelVege.Text = result["Veg"].ToString();
                } catch { }
                sql.CloseConn();
            }
        }

        protected void felveszButton_Click(object sender, EventArgs e)
        {
            string kezd = (!KoraTextBox.Text.Equals("") ? KoraTextBox.Text : "0") + ":" + (!KpercTextBox.Text.Equals("") ? KpercTextBox.Text : "0");
            string veg = (!VoraTextBox.Text.Equals("") ? VoraTextBox.Text : "0") + ":" + (!VpercTextBox.Text.Equals("") ? VpercTextBox.Text : "0");
            targykez.TargyLetrehoz(Session["User_ID"].ToString(), UjTargyTextBox.Text, kezd, veg, TargyLeirasTextBox.Text);
            TargyakListBox.DataBind();
        }

        protected void torolButton_Click(object sender, EventArgs e) {
            targykez.TargyTorl(Session["User_ID"].ToString(), TargyakListBox.SelectedValue.ToString());
            TargyakListBox.DataBind();
        }
    }
}